import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class _2合并区间 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] intervals = new int[n][2];
        for(int i = 0; i < n; i ++){
            intervals[i][0] = sc.nextInt();
            intervals[i][1] = sc.nextInt();
        }
        int[][] result  = merge(intervals);
        for(int i = 0 ; i < result.length; i++)
            System.out.println(result[i][0] +"," +result[i][1]);
    }
            public static int[][] merge(int[][] intervals) {
            Arrays.sort(intervals, (a, b) -> a[0] - b[0]); // 区间按左界排序
            List<int[]> resList = new ArrayList<>();
            int[] pre = intervals[0];
            for(int i = 1; i < intervals.length; i++){
                int[] cur = intervals[i];
                int preLeft = pre[0], preRight = pre[1];
                int curLeft = cur[0], curRight = cur[1];
                if(preRight >= curLeft){ // 发生合并，暂时不放入res中
                    pre = new int[] {preLeft, Math.max(preRight, curRight)};
                }
                else{
                    resList.add(pre); // pre与cur未发生合并，将pre放入res中
                    pre = cur;
                }
            }
            resList.add(pre); // 无论最后两个区间是否发生合并，剩余未加入res的区间都是pre
            return resList.toArray(new int[resList.size()][]);
        }
    }
